//
// Created by 王岩松 on 2020/3/19.
//
// Updated on 2020/3/25: add Sampled_xToLowIndex,resample

#ifndef SOUND_SOUND_H
#define SOUND_SOUND_H

#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <algorithm>
#include "audiofile.h"
#include "resample.h"

#define Function_RECTANGULAR  0
#define Function_TRIANGULAR  1
#define Function_HANNING  2
#define Function_HAMMING  3

using namespace std;

class sound {
    vector<double> data;
    int fs;
public:
    sound();
    sound(char* filename);
    sound(string filename);
    sound(vector<double> & a, int _fs);
    sound(double* a, int n, int _fs);
    void Free();
    double &operator [](int index) {
        return data[index];
    }
    // 返回vector
    vector<double> get() {return data;}
    // 给出输出的data的长度
    int getlength();
    // 给出输出的data的采样频率
    int getfrequency();
    // 用最大幅值归一化
    void norm();
    // 能量
    double getEnergy();
    // 分帧
    vector<vector<double>> enframe(int wlen, int inc, int windowType = Function_RECTANGULAR);
    // 窗函数
    static vector<double> windowFun (int winWidth, int windowType);
    // 截取为一段
    sound getSeg(int l, int r);
    sound getSeg(double tl, double tr);
    // t时刻对应的采样点
    int Sampled_xToLowIndex(double t);
    double Sampled_indexToX(int index);
    // 重采样
    sound resample(int samplingFrequency);
};


#endif //SOUND_SOUND_H
